<template>
    <div>
      <el-row style="text-align:left" :gutter="20">
        <el-col :span="4">
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-col>
      <el-col :span="4">
        <el-input v-model="input" placeholder="请输入类型名称"></el-input>
      </el-col>
      <el-col :span="4"></el-col>
        <el-button type="primary" @click="addnewType"></el-button>
      </el-row>
    </div>
</template>

<script>
import api from '../api'
export default {
  data(){
    return{
      options:[],
      value: 0,
      input:""
    }
  },
  mounted(){
    api.getGoodsCategory()
    .then((res) => { 
      let data = res.data.data;
      let att = data.filter((item) => item.parent == 0).map((item) => {
        return {label: item.typeName,value: item.typeId}
      })
      att.push({label: '一级分类',value: 0})
    })
  },
  methods :{
    addnewType(){
      api.addNewGoodsCategory(this.value,this.input)
      .then((res) => {
        if(res.status == 200){
          this.$message("添加类型成功")
        }
      })
    }
  }

}
</script>

<style>

</style>
